SaVaHtmlTable
in Chapter 2 for expanded details of this functionality.A problem with using flat files is the lack of a high-level, industry standard language like SQL. Without such a language, you lose data independence; you must write functions to support each additional query capability, and you have no index capability for searching large tables. In these cases you are building a legacy.
Suppose you wish to query for all employees who live in Utah, or all employees who earn more than $30,000, or all employees who live in Utah and earn more than $30,000, etc. The table component provides a tool for such needs.
The following sketch example shows how to use the Table Component.
contrib/table_ex,
in the Sapphire/Web distribution, contains an example start-up HTML file with both an Anchor, a Form, and customization files.
Apply
.
Edit|Activator Code ...
Enter the following code in the "Function Initialization Code" text box:
SaVaHtmlTable("SERVERNAME", "pubs2", "dbo.titles", SGESYBASE, SA_TABLE_TEMPLATE, NULL); return;where SERVERNAME is the name of your Sybase server, and dbo is assumed to be the table owner.
SaVaHtmlTable("ORACLE", "DATABASENAME", "SCOTT.TITLES", SGEORACLE, SA_TABLE_TEMPLATE, NULL); return;where DATABASENAME is the name of your Oracle database and SCOTT is assumed to be the table owner.
SaVaHtmlTable("SERVERNAME", "pubs2", "informix.titles", SGEINFORMIX, SA_TABLE_TEMPLATE, NULL); return;where SERVERNAME is the name of your Informix server and informix is assumed to be the table owner.
The SaVaHtmlTable
function takes a variable argument list of options which MUST BE null terminated. The constant SA_TABLE_TEMPLATE is defined to be the option string:
"SaHtmlTable.Template : True"This option allows this particular Table Component to be customized by an HTML template file as described later.
Now choose OK
in the activator code window and then OK
in the Object Bind Editor. Next choose the Edit|Options
menu from the project window. Set your start-up document in the Project Category. Also set the username and password for your database in your Test category, if not already set appropriately. Save your options as well as your project. Now Save, Build and Test your project. Click on the anchor. You will note that the Notes textbox is rather long. It is defined to be varchar 255. Also notice that the hotlist strings are too long. Your table may be customized to remedy these problems as follows:
Add the HTML customization file
titles_tab.htmlto your project for Sybase and Informix.
TITLES_tab.htmlfor Oracle.
The differences between Sybase, Oracle, and Informix are in case sensitivity. Bind the Form Activator to the NULL object using the Object Bind Editor; choose Apply
. Now choose Edit |Activator Code...
Enter the following code in the Function Initialization Code
text box:
SaVaHtmlTable("SERVERNAME", "pubs2", SaGetInputValue("TABLE_NAME"), SGESYBASE, SA_TABLE_TEMPLATE, NULL); return;where SERVERNAME is the name of your Sybase server.
SaVaHtmlTable("ORACLE", "DATABASENAME", SaGetInputValue("TABLE_NAME"), SGEORACLE, SA_TABLE_TEMPLATE, NULL); return;where DATABASENAME is the name of your Oracle database.
SaVaHtmlTable("SERVERNAME", "pubs2", SaGetInputValue("TABLE_NAME"), SGEINFORMIX, SA_TABLE_TEMPLATE, NULL); return;where
SERVERNAME
is the name of your Informix server. The difference between this code and the Anchor code is that the third parameter is not a hard-coded table name, but rather the input from a Form Element with the name, "TABLE_NAME". Choose Ok
in the activator code window, then Ok
in the Object Bind Editor. Now Save
, Build
and Test
your project. Enter your Table Name in the textbox and click OK
. If you choose the Titles Table as in the hard-coded case, you get the same customization as before. You can add selective customization files for other tables.
The Table Component has some limitations. It does not work with BLOB data. It also assumes that the table exists without relations to other tables. If you have set up certain integrity rules, then this may not be a problem. The source code for the Table Component can be found in the client/src
directory of the Sapphire/Web distribution, and the include files are found in the include
directory. The source code shows how you can use the Sapphire/Web API to deliver powerful components to your developers/user and other parts of your organization.
If you wish to learn more about the Table Component and how to make wide use of it, see the Bluestone demo at:
http://www.bluestone.com/sapphire/table/tdemo.html